package com.yuwen.yuwenRPC.registry;

/**
 * @ClassNameRegistryServiceMultiCache
 * @Description TODO
 * @Author钰玟
 * @Date2025/4/1 下午7:20
 * @Version 1.0
 **/

import com.yuwen.yuwenRPC.model.ServiceMetaInfo;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 支持多个服务的缓存
 */
public class RegistryServiceMultiCache {

    /**
     * 服务缓存
     */
    Map<String, List<ServiceMetaInfo>> serviceCache = new ConcurrentHashMap<>();

    /**
     * 写入缓存
     * @param serviceKey 写入缓存服务的 键名
     * @param newServiceCache 新的服务的元信息
     */
    void writeCache(String serviceKey, List<ServiceMetaInfo> newServiceCache) {
//        System.err.println("@@@@@Not Cache");

        this.serviceCache.put(serviceKey, newServiceCache);
    }

    /**
     * 读取缓存
     * @param serviceKey 读取所需缓存服务的键名
     * @return 所需服务的元信息
     */
    List<ServiceMetaInfo> readServiceCache(String serviceKey) {
//        System.err.println("@@@@@Cache"+serviceKey);
        return this.serviceCache.get(serviceKey);
    }

    /**
     * 删除对应键名服务的缓存
     * @param serviceKey 服务键名
     */
    void clearCache(String serviceKey) {
        this.serviceCache.remove(serviceKey);
    }


}
